import os, sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from sqlist import SqList

def delete_range(sq, x, y):
    """Delete all elements between x and y (inclusive) from sequential list
    Time: O(n), Space: O(1)"""
    k = 0  # count of elements to be deleted
    for i in range(sq.size):
        if sq.data[i] < x or sq.data[i] > y:
            sq.data[i - k] = sq.data[i]
        else:
            k += 1
    sq.size -= k  # update list size

if __name__ == "__main__":
    sq = SqList()
    sq.CreateList([1, 3, 4, 5, 7, 8, 9])
    delete_range(sq, 3, 7)
    print(sq.display())  # Expected: [1, 8, 9]